function publishLinearRegressResults(res,path,csvname,inputLabels,outcomeLabel)


%%%%%
% This function produces a csv file containing linear regression results.
%
% Inputs:
% res - structure containing a numeric field named "N" representing the total number of subjects and the following 3 fields from the "regress" function in Matlab: b, bint, stats
% path - string containing the path for the generated csv file
% csvname - string representing the csv file name
% inputLabels - 1D cell array of string labels of the input variables. should be in the same order as the b coefficients in res (note: don't include one for the constant term).
% outcomeLabel - string representing the label of the outcome variable.
%
% Written by Joon Lee, 2012
%%%%%


temp=cell(length(res.b)+8,4);

temp{1,1}='Outcome Variable:'; temp{1,2}=outcomeLabel;

temp{3,1}='N:'; temp{3,2}=res.N;
temp{4,1}='R^2:'; temp{4,2}=res.stats(1);
temp{5,1}='F-statistic:'; temp{5,2}=res.stats(2);
temp{6,1}='p-value for F:'; temp{6,2}=res.stats(3);
temp{7,1}='estimate of error variance:'; temp{7,2}=res.stats(4);

temp{9,2}='Beta'; temp{9,3}='95% CI Lower Bound'; temp{9,4}='95% CI Upper Bound'; temp{9,5}='p<0.05?';
for i=2:length(res.b)
    temp{8+i,1}=inputLabels{i-1};
    temp{8+i,2}=res.b(i);
    temp{8+i,3}=res.bint(i,1);
    temp{8+i,4}=res.bint(i,2);
    if res.bint(i,1)*res.bint(i,2)<=0
        temp{8+i,5}='N';
    else
        temp{8+i,5}='Y';
    end        
end

cd(path)
cell2csv(csvname,temp);

